package xkp.lesson4;

public class TestThread {
    public static void main(String[] args) {
        //此处匿名内部类+匿名对象   但是此处的匿名内部类的父类是谁??? Thread
        new Thread(){
            @Override
            public void run() {
                for (int i = 1; i <= 10; i++) {
                    //Thread.currentThread()当前线程
                    System.out.println(i + ":" + Thread.currentThread().getName()+"父类为 Thread");
                    //希望线程执行慢一点 可以使线程休眠
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();


        //此处也是用的是匿名内部类+匿名对象  此处匿名内部类的父亲是Runnable
        new Thread(new Runnable() {
            @Override
                    public void run() {
                        for (int i = 1; i <= 10; i++) {
                            //Thread.currentThread()当前线程
                            System.out.println(i + ":" + Thread.currentThread().getName()+"父接口为 Runnable");
                            //希望线程执行慢一点 可以使线程休眠
                            try {
                                Thread.sleep(10);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                }
            }
        }).start();
    }
}
